# -*- coding: utf-8 -*-
"""
Created on Sat Mar 15 20:19:42 2025

@author: lenovo
"""
from gsj_typhoon import split_str_id
import os
basedir = 'D:\\'




names = ['2023NH33','2023NH36','2023NH40','2023NH42','2023NH47']
years = [i[:4] for i in names]



def convert_date_str(date_path,year=None):
    date_str = os.path.basename(date_path)
    date_dir = os.path.dirname(date_path)
    if len(date_str) == 12:
        # 长度为 12 时，截取后 10 位
        return os.path.join( date_dir,date_str[2:] )
    elif len(date_str) == 8:
        # 长度为 8 时，在前面添加 '20'
        return os.path.join(date_dir,'20' + date_str)
    elif len(date_str) == 10:
        # 长度为10时，不用改变
        return os.path.join( date_dir, date_str)
    elif len(date_str) ==6:
        # 长度为6时
        return os.path.join(date_dir,year+date_str)
    else:
        # 长度不符合要求，返回原字符串
        print("日期格式错误：", date_str)
        return date_str



for i in range(len(names)):
    dirdate = os.path.join( basedir, f"met_data\\ty_ensemble\\{names[i]}" )
    pathdate = [os.path.join(dirdate,i) for i in os.listdir(dirdate)]
    for j in range(len(pathdate)):
        os.rename(pathdate[j], convert_date_str(pathdate[j],years[i]))
